package com.cie2.map.pages;

import java.util.List;

import org.apache.tapestry5.Asset;
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONArray;

import com.cie2.map.services.AreaEngine;
import com.cie2.map.services.JSONProcessor;

/*
@IncludeStylesheet("context:extjs/resources/css/ext-all.css")
@IncludeJavaScriptLibrary({"context:js/map.js"})					

*/

@IncludeStylesheet("context:style.css")
public class Map {

	// adding javascript library to the top of the generated html file
	@Inject
	@Path("context:js/map_editor.js")
	private Asset mapeditorLib;

	@Environmental
	private RenderSupport renderSupport;

	@SetupRender
	void addLibrary() {
		renderSupport.addScriptLink(mapeditorLib);
	}
	// end 
	
	@Inject
	private AreaEngine areaEngine;

	@Inject
	private JSONProcessor jsonProcessor;
	
	public JSONArray getArea() {
		System.out.println("=== Getting area in javascript ");

		List areaMarkers = areaEngine.getAllAreaMarkers();
		return jsonProcessor.marshal(areaMarkers);
		
	}
	
	Object onActionFromViewJakarta() {
		System.out.println("=== View Jakarta ");
	
		return Login.class;
	}
}
